﻿using System;
using System.Runtime.CompilerServices;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using Ths.Components.Common;
using Ths.Framework;
using Ths.Components.Dictionary;
using Ths.Components.Dictionary.Entity;
using Ths.Components.Excel;
using Ths.Components;
using System.Configuration;
using System.Web.Security;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;
using SafetyRecordData.Data.DAL;
public partial class DistressManage_HurtCount : Base
{
    Db List = new Db();
    public static string CountsLabel, AllPageLabel, CurrentlyPageLabel, SqlStrStart, SqlStrMid, SqlStr, SqlStrStartCount, SqlStrCount;
    DAHurtDistress dal = new DAHurtDistress();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            if (Session["ResponseRemark"].ToString() == "局级")
            {
                DataBindToGridview("order by id asc");
            }
            else
            {
                Response.Redirect("HurtDetailCount.aspx?bumenid=" + new DAHurtDistress().GetTopDepartMentID(Session["BuMenID"].ToString()));
            }
            
            

        }
    }

    #region 初始化


    #endregion

    //用于构造DbParameter数组
    List<DbParameter> parameterList = new List<DbParameter>();

    public void DataBindToGridview(string Sqlsort)
    {
        this.GridView1.PageSize = 100;
        DbParameter theSqlParameter = null;
        theSqlParameter = dal.DBFactory.CreateParameter("@StartTime", "" + Convert.ToString(txtStartTime.Value.Trim()) + "");
        parameterList.Add(theSqlParameter);
        theSqlParameter = dal.DBFactory.CreateParameter("@EndTime", "" + Convert.ToString(this.txtEndTime.Value) + "");
        parameterList.Add(theSqlParameter);
        theSqlParameter = dal.DBFactory.CreateParameter("@UserName", "" + Convert.ToString(Session["username"].ToString()) + "");
        parameterList.Add(theSqlParameter);
        theSqlParameter = dal.DBFactory.CreateParameter("@IsAll", chkAll.Checked ? "1" : "0");
        parameterList.Add(theSqlParameter);
        string isAll = chkAll.Checked ? "1" : "0";
        string where = "'" + Session["username"].ToString() + "','" + txtStartTime.Value.Trim() + "','" + this.txtEndTime.Value + "','" + isAll + "'";
        DataTable dt = dal.GetHurtListCount(parameterList.ToArray(), "", where);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        //SqlStrStart = "select * from NotHurtDistress where 1=1";
        //SqlStrStartCount = "select count(id) from NotHurtDistress where 1=1";

        //SqlStrMid = string.Empty;
        //SqlStr = SqlStrStart + SqlStrMid;//查询
        //SqlStrCount = SqlStrStartCount + SqlStrMid;//查询个数

        //if (Request.QueryString["key"] != null)
        //{
        //    string SQL_GetList_xs = "" + SqlStr + " " + Sqlsort + "";
        //    GridView1.DataSource = List.GetGrid_Pages_not(SQL_GetList_xs);
        //    GridView1.DataBind();

        //    string SQL_GetCount = SqlStrCount;
        //    CountsLabel = "" + List.GetCount(SQL_GetCount) + "";

        //}
        //else
        //{
        //    string SQL_GetCount = "select count(appid) from  NotHurtDistress";
        //    CountsLabel = "" + List.GetCount(SQL_GetCount) + "";

        //    string SQL_GetList_xs = "select * from NotHurtDistress " + Sqlsort + "";
        
        //}


    }







    #region GridView基本信息
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataControlRowType itemType = e.Row.RowType;
        if (e.Row.RowType != DataControlRowType.Header)
        {
            e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
            e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";

            Label lblCompany = (Label)e.Row.FindControl("lblCompany");
            Label lblID = (Label)e.Row.FindControl("lblID");
            Label lblChildID = (Label)e.Row.FindControl("lblChildID");
            if (lblCompany != null && lblID != null && lblChildID != null)
            {
                Label lblBumen = (Label)e.Row.FindControl("LabVisible");
                if (lblID.Text.Trim() != lblChildID.Text.Trim())
                {
                    lblCompany.Text = "<a href='hurtdetailcount.aspx?bumenid=" + lblBumen.Text + "&starttime1=" + this.txtStartTime.Value.Trim() + "&endtime1=" + this.txtEndTime.Value.Trim() + "'>" + lblCompany.Text + "</a>";
                }
            }

            Label lblCount = (Label)e.Row.FindControl("lblAllCount");
            if (lblCount != null && lblID != null)
            {
                lblCount.Text = "<a href='#' onclick=\"openunit('" + lblID.Text.Trim() + "','" + this.txtStartTime.Value + "','" + this.txtEndTime.Value + "')\">" + lblCount.Text + "</a>";
            }
        }
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sql = "";

        if (ViewState["SortDirection"] == null || ViewState["SortDirection"].ToString().CompareTo("") == 0)
        {
            ViewState["SortDirection"] = " desc";
        }
        else
            ViewState["SortDirection"] = "";

        sql = " order by " + e.SortExpression + ViewState["SortDirection"];


        DataBindToGridview(sql);
    }


    #endregion


    protected void btnSave_Click(object sender, EventArgs e)
    {
        this.DataBindToGridview("");
    }
}
